package com.zhida.jiyangcenter.utils

import chooongg.base.utils.logE
import chooongg.http.APIException
import chooongg.http.HttpCallback
import kotlinx.coroutines.*


fun <T> CoroutineScope.request(api: suspend() -> T, response: HttpCallback<T>) {
    launch(Dispatchers.IO) {
        try {
            response.response(api.invoke())
        } catch (e: Throwable) {
            if (e is CancellationException) return@launch
            response.allotErrorDirection(APIException(e))
        }
    }
}